﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Windows.Controls;

namespace TJDevHouse.Starcraft.MapAnalyser.MapDrawing
{
	abstract public class MapLayer
	{
		private Canvas _layerCanvas = new Canvas();

		/// <summary>
		/// Whether this layer has been rendered or not
		/// </summary>
		public bool IsRendered { get; protected set; }

		/// <summary>
		/// The canvas for this layer
		/// </summary>
		public Canvas LayerCanvas {
			get
			{
				return _layerCanvas;
			}
			protected set
			{
				_layerCanvas = new Canvas();
			}
		}



		/// <summary>
		/// Render the layer onto the specified MapDisplay
		/// </summary>
		/// <param name="display"></param>
		public virtual void Render(MapDisplay display)
		{
			//only do the actual rendering when needed
			//if (!IsRendered)
			//{
				IsRendered = true;

				LayerCanvas.Children.Clear();

				LayerCanvas.Width = (display.WalkTileSize * display.Map.MapWalkableWidth) + display.WalkTileSize;
				LayerCanvas.Height = display.WalkTileSize * display.Map.MapWalkableHeight;

				RenderLayer(display);	
			//}

			//add the layer's canvas to the map display's canvas
			display.MapCanvas.Children.Add(LayerCanvas);
		}

		/// <summary>
		/// Render the layer onto the map display
		/// </summary>
		protected abstract void RenderLayer(MapDisplay display);
	}
}
